#include "list.h"
#include "ui_list.h"
#include <QDebug>

List::List(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::List)
{
    ui->setupUi(this);
}

List::~List()
{
    delete ui;
}

void List::on_pushButton_add_clicked()
{
    QString value = ui->lineEdit->text();
    if (!value.isEmpty())
    {
        ui->listWidget->addItem(value);
    }
}



void List::on_pushButton_del_clicked()
{
    int row = ui->listWidget->currentRow();
    if (row < 0) return;
    ui->listWidget->takeItem(row);
}

void List::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if (current)
    {
        qDebug() << "当前选中的是: " << current->text();
    }
    if (previous)
    {
        qDebug() << "上次选中的是: " << previous->text();
    }
}
